#ifndef PARSER_DONE_H
#define PARSER_DONE_H

#include "ParserBase.h"
#include "CommandDone.h"

/**
 * Handler for "done" commands. 
 * 
 * Reads in either a task index, or a search term. 
 * 
 * Since there is no observable way of identifying whether a request is a
 * search term or a task index when the argument is just a number, 
 * returning a task index (if possible) takes priority.
 @author Ling Chun Kai
*/

class ParserDone : public ParserBase {
public:
	ParserDone(ParserBase* _nextParser);
private:
	enum {INSTRUCTION_POS = 1, ARGUMENTS_POS, NUM_MAJOR_SEGMENTS};
	enum CommandType {DONE_TASKID, DONE_SEARCHTERM, INVALID};

	// The following are regex constants used for parsing
	static const string regexInstructionAndArguments;

	static const string regexInstructionDone;
	
	static const string regexArgumentDoneTaskID;
	static const string regexArgumentDoneSearchTerm;

	// The following are the locations for parsed segments for the expressions
	static const int ARGUMENT_POS_DONE_TASKID = 1;
	static const int ARGUMENT_POS_DONE_SEARCHTERM = 1;

	bool tryParse(string userCommand, CommandBase*& parsedCommand);

	bool getInstructionAndArguments(const string& userCommand, 
										string& instruction, 
										string& arguments);

	// This method checks that the instruction is of the type 'done'
	bool checkInstruction(const string& instruction);

	// This method finds out what kind of "done" command the user entered
	CommandType categorizeDoneCommand(const string& arguments, smatch& matchingArguments);

	void parseDone(CommandBase*& parsedCommand,
				  const string& arguments);
};

#endif